/*********************************************************************
	Rhapsody	: 7.5.2
	Login		: Administrator
	Component	: Lib
	Configuration 	: DefaultConfig
	Model Element	: Display
//!	Generated Date	: Wed, 8, Dec 2010 
	File Path	: Lib/DefaultConfig/RobotPkg/Display.java
*********************************************************************/

package RobotPkg;

//## auto_generated
import com.ibm.rational.rhapsody.oxf.*;
//## auto_generated
import com.ibm.rational.rhapsody.oxf.states.*;

//----------------------------------------------------------------------------
// RobotPkg/Display.java                                                                  
//----------------------------------------------------------------------------

//## package RobotPkg 


//## class Display 
public class Display implements RiJStateConcept {
    
    public Reactive reactive;		//## ignore 
    
    protected KeyReader itsKeyReader;		//## classInstance itsKeyReader 
    
    protected RobotController itsRobotController;		//## classInstance itsRobotController 
    
    //#[ ignore 
    public static final int RiJNonState=0;
    public static final int waitForKeys=1;
    //#]
    protected int rootState_subState;		//## ignore 
    
    protected int rootState_active;		//## ignore 
    
    
    //## statechart_method 
    public RiJThread getThread() {
        return reactive.getThread();
    }
    
    //## statechart_method 
    public void schedTimeout(long delay, long tmID, RiJStateReactive reactive) {
        getThread().schedTimeout(delay, tmID, reactive);
    }
    
    //## statechart_method 
    public void unschedTimeout(long tmID, RiJStateReactive reactive) {
        getThread().unschedTimeout(tmID, reactive);
    }
    
    //## statechart_method 
    public boolean isIn(int state) {
        return reactive.isIn(state);
    }
    
    //## statechart_method 
    public boolean isCompleted(int state) {
        return reactive.isCompleted(state);
    }
    
    //## statechart_method 
    public RiJEventConsumer getEventConsumer() {
        return (RiJEventConsumer)reactive;
    }
    
    //## statechart_method 
    public void gen(RiJEvent event) {
        reactive._gen(event);
    }
    
    //## statechart_method 
    public void queueEvent(RiJEvent event) {
        reactive.queueEvent(event);
    }
    
    //## statechart_method 
    public int takeEvent(RiJEvent event) {
        return reactive.takeEvent(event);
    }
    
    // Constructors
    
    //## auto_generated 
    public  Display(RiJThread p_thread) {
        reactive = new Reactive(p_thread);
        initRelations(p_thread);
    }
    
    //## operation processKey(char) 
    public void processKey(char key) {
        //#[ operation processKey(char) 
        if(key == 's') itsRobotController.gen(new evOnOff());
        else if(key == 'q') System.exit(1);
        else if(key >= '0' && key <= '6') {
        	int numKey = key - '0';
        	if(itsRobotController.itsSensor.get(numKey).getLine() == false)
        		itsRobotController.itsSensor.get(numKey).gen(new lineSeen());
        	else     
        		itsRobotController.itsSensor.get(numKey).gen(new lineNotSeen());
        }
        
        //#]
    }
    
    //## auto_generated 
    public KeyReader getItsKeyReader() {
        return itsKeyReader;
    }
    
    //## auto_generated 
    public void __setItsKeyReader(KeyReader p_KeyReader) {
        itsKeyReader = p_KeyReader;
    }
    
    //## auto_generated 
    public void _setItsKeyReader(KeyReader p_KeyReader) {
        if(itsKeyReader != null)
            {
                itsKeyReader.__setItsDisplay(null);
            }
        __setItsKeyReader(p_KeyReader);
    }
    
    //## auto_generated 
    public KeyReader newItsKeyReader(RiJThread p_thread) {
        itsKeyReader = new KeyReader(p_thread);
        itsKeyReader._setItsDisplay(this);
        return itsKeyReader;
    }
    
    //## auto_generated 
    public void deleteItsKeyReader() {
        itsKeyReader.__setItsDisplay(null);
        itsKeyReader=null;
    }
    
    //## auto_generated 
    public RobotController getItsRobotController() {
        return itsRobotController;
    }
    
    //## auto_generated 
    public RobotController newItsRobotController(RiJThread p_thread) {
        itsRobotController = new RobotController(p_thread);
        return itsRobotController;
    }
    
    //## auto_generated 
    public void deleteItsRobotController() {
        itsRobotController=null;
    }
    
    //## auto_generated 
    protected void initRelations(RiJThread p_thread) {
        itsKeyReader = newItsKeyReader(p_thread);
        itsRobotController = newItsRobotController(p_thread);
    }
    
    //## auto_generated 
    public boolean startBehavior() {
        boolean done = true;
        done &= itsKeyReader.startBehavior();
        done &= itsRobotController.startBehavior();
        done &= reactive.startBehavior();
        return done;
    }
    
    //## ignore 
    public class Reactive extends RiJStateReactive {
        
        // Default constructor 
        public Reactive() {
            this(RiJMainThread.instance());
        }
        
        
        // Constructors
        
        public  Reactive(RiJThread p_thread) {
            super(p_thread);
            initStatechart();
        }
        
        //## statechart_method 
        public boolean isIn(int state) {
            if(rootState_subState == state)
                {
                    return true;
                }
            return false;
        }
        
        //## statechart_method 
        public boolean isCompleted(int state) {
            return true;
        }
        
        //## statechart_method 
        public void rootState_entDef() {
            {
                rootState_enter();
                rootStateEntDef();
            }
        }
        
        //## statechart_method 
        public int rootState_dispatchEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(rootState_active == waitForKeys)
                {
                    res = waitForKeys_takeEvent(id);
                }
            return res;
        }
        
        //## auto_generated 
        protected void initStatechart() {
            rootState_subState = RiJNonState;
            rootState_active = RiJNonState;
        }
        
        //## statechart_method 
        public void waitForKeys_enter() {
            rootState_subState = waitForKeys;
            rootState_active = waitForKeys;
            waitForKeysEnter();
        }
        
        //## statechart_method 
        public void waitForKeys_entDef() {
            waitForKeys_enter();
        }
        
        //## statechart_method 
        public int waitForKeys_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(evKeyPress.evKeyPress_RobotPkg_id))
                {
                    res = waitForKeysTakeevKeyPress();
                }
            
            return res;
        }
        
        //## statechart_method 
        public void waitForKeysEnter() {
        }
        
        //## statechart_method 
        public int rootState_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            return res;
        }
        
        //## statechart_method 
        public int waitForKeysTakeevKeyPress() {
            evKeyPress params = (evKeyPress) event;
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            waitForKeys_exit();
            //#[ transition 1 
            processKey(params.key);
            //#]
            waitForKeys_entDef();
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public void rootState_enter() {
            rootStateEnter();
        }
        
        //## statechart_method 
        public void rootStateEnter() {
        }
        
        //## statechart_method 
        public void waitForKeys_exit() {
            waitForKeysExit();
        }
        
        //## statechart_method 
        public void rootState_exit() {
            if(rootState_subState == waitForKeys)
                {
                    waitForKeys_exit();
                }
            rootState_subState = RiJNonState;
            rootStateExit();
        }
        
        //## statechart_method 
        public void rootStateEntDef() {
            waitForKeys_entDef();
        }
        
        //## statechart_method 
        public void waitForKeysExit() {
        }
        
        //## statechart_method 
        public void rootStateExit() {
        }
        
    }
}
/*********************************************************************
	File Path	: Lib/DefaultConfig/RobotPkg/Display.java
*********************************************************************/

